package org.openstack;

import org.openstack.service.auth.AuthOS;
import org.openstack4j.api.OSClient.OSClientV3;
import org.openstack4j.api.telemetry.SampleService;
import org.openstack4j.model.common.Identifier;
import org.openstack4j.model.telemetry.MeterSample;
import org.openstack4j.model.telemetry.Sample;
import org.openstack4j.model.telemetry.SampleCriteria;
import org.openstack4j.openstack.OSFactory;
import org.openstack4j.openstack.telemetry.internal.SampleServiceImpl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

public class App {

    public static void main(String[] args) {



//        OSClientV3 os = AuthOS.getOSClient();

//        ComputeService computeService = new ComputeServiceImpl();
//        List<? extends Hypervisor> hypervisors = computeService.hypervisors().list();
//        for (Hypervisor h : hypervisors) {
//            System.out.println(h);
//        }
//        HypervisorStatistics statistics = computeService.hypervisors().statistics();
//        System.out.println(statistics);

//        List<? extends Server> servers = os.compute().servers().listAll(true);
//        for (Server s : servers) {
//            System.out.println(s);
//        }

//        ResourceService resourceService = new ResourceServiceImpl();
//        List<? extends Resource> resources = resourceService.list();
//        for (Resource r : resources) {
//            System.out.println(r);
//        }

//		ComputeService service = new ComputeServiceImpl();
//		Map<String, String> filteringParams = new HashMap<>();
//		filteringParams.put("name", "compute1");
//        for (Server s : service.servers().listAll(true)) {
//            System.out.println(s.getName() + " " + s.getInstanceName() + " " + s.getHost() + " " + s.getHostId() + " "
//            + s.getHypervisorHostname());
//            System.out.println(s);
//        }

//        // Meters
//        List<? extends Meter> meters = os.telemetry().meters().list();
//        for (Meter meter : meters) {
//			System.out.println(meter);
//		}
//
//
        // Samples
//        List<? extends MeterSample> samples = os.telemetry().meters().samples("memory");
//        for (MeterSample meterSample : samples) {
//            System.out.println(meterSample);
//        }

//        SampleService sampleService = new SampleServiceImpl();
//        SampleCriteria sc = new SampleCriteria()
//                .resource("1eea344d-79c4-408e-8fac-c8801e0fd702")
//                .project("043b9d0dfbc44982b6eda7857975fce9")
//                .timestamp(SampleCriteria.Oper.GT, System.currentTimeMillis() - (24 * 60 * 60 * 1000))
//                .timestamp(SampleCriteria.Oper.LT, System.currentTimeMillis());
//        boolean result = true;
//        for (Sample s : sampleService.list(sc)) {
//            if (!s.getResourceId().equals("1eea344d-79c4-408e-8fac-c8801e0fd702")
//                    || !s.getProjectId().equals("043b9d0dfbc44982b6eda7857975fce9")
//                    || !Timestamp.valueOf(s.getTimestamp()).after(new Timestamp(System.currentTimeMillis() - (24 * 60 * 60 * 1000)))
//                    || !Timestamp.valueOf(s.getTimestamp()).before(new Timestamp(System.currentTimeMillis())))
//            System.out.println(s);
//        }

//        // Statistics
//		List<? extends Statistics> stats = os.telemetry().meters().statistics("image.size");
//		for (Statistics statistics : stats) {
//			System.out.println(statistics);
//		}


    }

}
